<?php
/**
 * Created by IntelliJ IDEA.
 * User: yoli
 * Date: 12/25/15
 * Time: 4:24 PM
 */

namespace core\web;


use yii\helpers\Json;

class View extends \yii\web\View
{
    /**
     * Use Smarty as default template.
     * @var string the default view file extension. This will be appended to view file names if they don't have file extensions.
     */
    public $defaultExtension = 'tpl';
    //public $defaultExtension = 'php';


    /**
     * Renders a json object in response.
     *
     * This method is similar to [[render()]], But it only return Json data.
     *
     * @param array $params the parameters (name-value pairs) that will be converted as json object.
     * @return string json Object
     * @see render()
     */
    public function renderJson($params = [])
    {
        ob_start();
        ob_implicit_flush(false);

        header('Content-type: application/json; charset=UTF-8');
        echo Json::encode($params);

        return ob_get_clean();
    }

}


